/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package testonlineconnectdb;


import java.util.ArrayList;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

/**
 *
 * @author AngelKid
 */
public class SaxProcessUpdateQuestion extends DefaultHandler {
    int count;
    int maxCode;
    String pathNewXML;
    String pathBankQuestion;
    boolean bMaCauHoi,flagDuplicateCode,bDoKho;
    ArrayList qEasy;
    ArrayList qNormal;
    ArrayList qDifficult;
    int questionCode,questionDifficult;
    public SaxProcessUpdateQuestion()
    {
        questionCode = questionDifficult = 0;
        qEasy = new ArrayList();
        qNormal = new ArrayList();
        qDifficult = new ArrayList();
        bMaCauHoi = flagDuplicateCode = bDoKho = false;
        count = maxCode = 0;
    }
    public int GetMaxCode()
    {
        return maxCode;
    }
    public ArrayList GetEasyQuestion()
    {
        return qEasy;
    }
    public ArrayList GetNormalQuestion()
    {
        return qNormal;
    }
    public ArrayList GetDifficultQuestion()
    {
        return qDifficult;
    }
            
    @Override
    public void startElement(String uri, String localName, String qName,Attributes attributes){
        if(qName.equals("CauHoi"))
        {
            count++;
        }
        if(qName.equals("MaCauHoi"))
        {
            bMaCauHoi = true;
        }
        if(qName.equals("DoKho"))
        {
            bDoKho = true;
        }
    }
    @Override
    public void characters(char[] ch, int start, int length)
    {
        String str = new String(ch,start,length);
        if(bMaCauHoi)
        {
            questionCode = Integer.parseInt(str);
            maxCode = questionCode>maxCode?questionCode:maxCode;
        }
        if(bDoKho)
        {
            questionDifficult = Integer.parseInt(str);
        }
    }
    @Override 
    public void endElement(String uri, String localName, String qName)
    {
        if(qName.equals("CauHoi"))
        {
            bMaCauHoi = false;
            switch(questionDifficult)
            {
                case 1: qEasy.add(questionCode); break;
                case 2: qNormal.add(questionCode); break;
                case 3: qDifficult.add(questionCode); break;
            }
        }
        if(qName.equals("DoKho"))
        {
            bDoKho = false;
        }
        if(qName.equals("MaCauHoi"))
        {
            bMaCauHoi = false;
        }
    }
    @Override
    public void endDocument()
    {
        //System.out.println("Count: " + count +"\nMaxCode: "+maxCode);
        
    }
    
}
